<?php

class Post extends AppModel
{
	var $name = 'Post';
	var $belongsTo = array(
		'User' 	=>	array('classname' => 'User',
						'foreignKey' => 'user_id'),
		'Subject' => array('classname'=> 'Subject',
						'foreignKey' => 'subject_id'),
		'Copyright' => array('classname'=>'Copyright',
						'foreignKey'=>'copyright_id')
		
	);
	
	var $hasMany = array(
			'Comment' => array('className' => 'Comment',
								'foreignKey' => 'post_id')
	);
	
	//var $validate = array('title' => array('rule' => array('custom', '/^[0-9a-z]+$/i')), 'byline'=>array('rule' => array('custom', '/^[0-9a-z]+$/i')), 'body'=>array('rule' => array('custom', '/^[0-9a-z]+$/i')));
	function beforeSave()
    {
        if (empty($this->id))
        {
            $this->data[$this->name]['url'] = $this->getUniqueUrl($this->data[$this->name]['title'], 'url');
        }
        
        return true;
    } 
	
	function afterSave()
	{
		@unlink(CACHE.'views'.DS.'element__getposts');
	}
	
	function afterDelete()
	{
		@unlink(CACHE.'views'.DS.'element__getposts');
	}
}
?>